﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RedirctDemo2
{
  public partial class Site1 : System.Web.UI.MasterPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      //RedirctHelper.AutoRedirct(Request.Url, RequestMode.FromHttp2Https, RedirctMode.Redirect, "https://www.baidu.com/");

      AutoRedirct();
    }

    private void AutoRedirct()
    {
      Uri uri = Request.Url;

      if (uri.Scheme.Equals("http", StringComparison.CurrentCultureIgnoreCase))
      {
        var redirct = string.Format("{0}://{1}{2}", "https", uri.Authority, uri.PathAndQuery);

        Response.Redirect(redirct, true);
      }
    }
  }
}